package com.zcb.qingshoudan.fragment;

import android.annotation.SuppressLint;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.zcb.qingshoudan.R;
import com.zcb.qingshoudan.activity.GatheringQRCodeActivity;

/**
 * Created by admin on 2016/11/24.
 * 底部菜单：收款Fragment
 */
@SuppressLint("ValidFragment")
public class GatheringFragment extends Fragment implements View.OnClickListener{
    private Button payOnceButton;
    private EditText gatheringMoneyED;

    private IFragment iFragment;
    private Context mContext;
    private String money;

    public GatheringFragment() {
    }

    public GatheringFragment(Context mContext,IFragment iFragment) {
        this.iFragment = iFragment;
        this.mContext=mContext;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view =inflater.inflate(R.layout.fragment_gathering,container,false);
        initView(view);
        return view;
    }

    private void initView(View view){
        payOnceButton= (Button) view.findViewById(R.id.gathering_atonce);
        payOnceButton.setOnClickListener(this);
        gatheringMoneyED = (EditText) view.findViewById(R.id.gathering_money_ed);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.gathering_atonce:
                openActivity();
                break;
        }
    }

    private void openActivity(){
        money=gatheringMoneyED.getText().toString();
        if (money.equals("")){
            Toast.makeText(mContext,"请输入金额",Toast.LENGTH_LONG).show();
        }else {
        Intent intent=new Intent(mContext,GatheringQRCodeActivity.class);
        intent.putExtra("QRCodeInfo",money);
        iFragment.openAty(intent);
        }

    }
}
